function submitAction(actionUrl, checkvalid) {
	if(checkvalid) {
		if($('#pmsTopForm').valid()) {
			return submitForm(actionUrl);
		}
	} else {
		return submitForm(actionUrl);
	}
}

function submitForm(actionUrl) {
	try {
        document.forms['pmsTopForm'].action = actionUrl;
        document.forms['pmsTopForm'].submit();
        return true;
    } catch(e) {
        return false;
    }
}

function confirmAction(actionUrl, title, message) {
	var okButton = "Ok";
	if(okButtonLabel != null)
		okButton = okButtonLabel;
	
	var cancelButton = "Cancel";
	if(cancelButtonLabel != null)
		cancelButton = cancelButtonLabel;
	
	var defaultTitle = "PMS Confirmation Dialog";
	if(title != null)
		defaultTitle = title;
	
	var defaultMessage = "Are you sure?";
	if(message != null)
		defaultMessage = message;
	
	var buttonOpts = {};
	buttonOpts[okButton] = function () {
		$( this ).dialog( "close" );
        try {
	        document.forms['pmsTopForm'].action = actionUrl;
	        document.forms['pmsTopForm'].submit();
	        return true;
	    } catch(e) {
	        return false;
	    }
	};
	buttonOpts[cancelButton] = function () {
		$( this ).dialog( "close" );
	};
	
	$("#dialog-confirm").dialog({
		buttons: buttonOpts
    });
	
	$("#dialog-confirm").dialog('option', 'title', defaultTitle);
	if(!$('#dialog-confirm').dialog('isOpen')){
		$("label", "#dialog-confirm").text(defaultMessage);
        $('#dialog-confirm').dialog('open');
    }
	return false;
}

function loadDdsmoothMenu(id, direction) {
	ddsmoothmenu.init({
	 mainmenuid: id, //menu DIV id
	 orientation: direction, //Horizontal or vertical menu: Set to "h" or "v"
	 classname: 'ddsmoothmenu', //class added to menu's outer DIV
	 customtheme: ["#1c5a80", "#18374a"],
	 contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
	});
}

function toggleSubCategories(categoryId, subCategoriesSize) {
	var enable = $("#category"+categoryId).prop('checked');
	for(var i = 0; i < subCategoriesSize; i ++) {
		if(enable == true) {
			$("#"+categoryId+"subCategory"+i).removeAttr("disabled");
		} else {
			$("#"+categoryId+"subCategory"+i).attr("disabled", true);
		}
	}
}

function toggleMainSubCategory(categoryId, index) {
	var enable = $("#"+categoryId+"subCategory"+index).prop('checked');
	if(enable == true) {
		$("#"+categoryId+"mainSubCategory"+index).removeAttr("disabled");
	} else {
		$("#"+categoryId+"mainSubCategory"+index).attr("disabled", true);
		$("#"+categoryId+"mainSubCategory"+index).attr("checked", false);
	}
}

function showAboutUs() {
	var buttonOpts = {};
	var closeButton = "Close";
	var defaultTitle = "About PMS Web Application";
	
	buttonOpts[closeButton] = function () {
		$( this ).dialog( "close" );
	};
	$("#dialog-information").dialog({
		buttons: buttonOpts
    });
	
	$("#dialog-information").dialog('option', 'title', defaultTitle);
	if(!$('#dialog-information').dialog('isOpen')){
        $('#dialog-information').dialog('open');
    }
}